package com.haust.dianqi.web;

import com.haust.dianqi.pojo.User;
import com.haust.dianqi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @Auther: csp1999
 * @Date: 2020/04/27/9:38
 * @Description:
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
    * @方法描述: 登录操作
    * @参数集合: [user]
    * @返回类型: java.lang.String
    * @作者名称: csp1999
    * @日期时间: 2020/4/27 9:40
    */
    @PostMapping("/login")
    public String login(User user, HttpSession session){
        User login = userService.login(user);
        System.out.println(login);

        if (login!=null){
            session.setAttribute("user",login);
            return "redirect:/addArticle";
        }else{
            return "redirect:/login";
        }
    }
}
